<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","kdvendor");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_setup_vendor.php";
$FileTemplate  = "ais_setup_vendor_list.html";
$PageSize      = 10 ;
$HTMLGridList  = "VendorGrid";
//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}

//Initiate Database Table For Search;
$FNama = GetParam("vendorSearch","");
$FCode = GetParam("vendorCodeSearch","");
$FType = GetParam("vendorTypeSearch","");
//******* DATABASE FORM QUERY ***********
$SQL = "SELECT * FROM `tblvendor` ";
$SQLCount = "SELECT count(*) FROM `tblvendor` ";

if ($FNama) 
	if (strlen($WHERE)) $WHERE .= " AND "." nama like '".$FNama."%'";
	else $WHERE .= " nama like '".$FNama."%'";	
if ($FCode) 
	if (strlen($WHERE)) $WHERE .= " AND "." kdvendor like '".$FCode."%'";
	else $WHERE .= " kdvendor like '".$FCode."%'";
if ($FType) 
	if (strlen($WHERE)) $WHERE .= " AND "." kdvendor like '".$FType."%'";
	else $WHERE .= " kdtype like '".$FType."%'";
        
	if (strlen($WHERE)) $WHERE .= " AND "." ktrasl = '".GetOfficeID()."'";
	else $WHERE .= " ktrasl = '".GetOfficeID()."'";
        
	if (strlen($WHERE))	$WHERE = " WHERE ".$WHERE;
	else $WHERE = " WHERE 1";
        

$SQL = $SQL.$WHERE." ORDER BY kdvendor";
$SQLCount = $SQLCount.$WHERE." ORDER BY kdvendor";

//print $SQL;
//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ; 

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName;	
	for ($x=1;$x<=$PageSize;$x++) {				
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("tblvendor",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
	
}

?>